package com.um.jdy.platform.shop.controller;

import com.um.jdy.common.shop.entity.dto.CourierDTO;
import com.um.jdy.common.shop.entity.po.Courier;
import com.um.jdy.common.shop.entity.vo.CourierVO;
import com.um.jdy.common.shop.service.CourierService;
import com.um.jdy.platform.shop.entity.dto.CourierExportDTO;
import com.um.jdy.platform.shop.entity.vo.CourierErrorVO;
import com.um.jdy.platform.shop.entity.dto.CourierPageDTO;
import com.um.jdy.platform.shop.manager.CourierManager;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.RequestJson;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.orm.controller.BasePlusController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.ExportParams;
import com.um.springboot.starter.orm.params.ListDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 控制器：物流公司表
 */
@RestController
@RequestMapping("/api/v1/cms/shop/courier")
@Api(tags = "CourierController", description = "物流公司表")
@ApiPermission("courier")
@TokenRequired
public class CourierController extends BasePlusController<CourierManager, CourierService, Courier, CourierDTO, CourierVO, CourierPageDTO, ListDTO> {

    @ApiPermission("export")
    @ApiOperation("导出物流公司")
    @PostMapping("/export_courier_page")
    public Response exportCourierPage(@RequestBody CourierExportDTO params) {
        ExportParams exportParams = params.toExportParams(
                new String[]{"name", "code"},
                new String[]{"name", "code"});
        return manager.exportCourierPage(exportParams);
    }

    @ApiPermission("import")
    @ApiOperation("导入物流公司")
    @PostMapping("/import")
    public Response<List<CourierErrorVO>> importExcel(@RequestJson String path) {
        return manager.importExcel(path);
    }

    @ApiPermission("list")
    @ApiOperation("物流公司列表")
    @GetMapping("/get_all")
    public Response<List<CourierVO>> getAll() {
        return Response.success(manager.getAll());
    }

}
